﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using MaxStudio.Concrete.DBUtility;
namespace MaxStudio.Concrete.Server.Dao
{
    public partial class ConcreteDaoDataContext : System.Data.Linq.DataContext
    {
        #region user
        public List<tb_Customer> GetAllCustomerList(int currentPage, int PageSize)
        {

            var query = (from obj in this.tb_Customers
                         where obj.IsDelete == 0
                         select obj).ToList();
            return query;
        }

        public tb_Customer GetCustomerById(int id)
        {
            return this.tb_Customers.SingleOrDefault(tb_Customers => tb_Customers.Id == id);
        }

        public void CreateCustomer(tb_Customer instance)
        {
            instance.CreateDate = DateTime.Now;
            instance.CreateBy = 1;
            instance.ModifyDate = DateTime.Now;
            instance.ModifyBy = 1;
            tb_Customers.InsertOnSubmit(instance);
            this.SubmitChanges();
        }

        public void ModifyCustomer(tb_Customer instance)
        {
             tb_Customer modifyInstance = this.tb_Customers.SingleOrDefault(p => p.Id == instance.Id);
             modifyInstance.Address = instance.Address;
             modifyInstance.BankInformation = instance.BankInformation;
             modifyInstance.ComeFrom = instance.ComeFrom;

             modifyInstance.CustomerLevel = instance.CustomerLevel;
             modifyInstance.Description = instance.Description;
             modifyInstance.Fax = instance.Fax;
             modifyInstance.KindOfCompany = instance.KindOfCompany;
             modifyInstance.Name = instance.Name;
             modifyInstance.NumOfEmp = instance.NumOfEmp;
             modifyInstance.Principal = instance.Principal;
             modifyInstance.Stauts = instance.Stauts;
             modifyInstance.Tel1 = instance.Tel1;
             modifyInstance.Tel2 = instance.Tel2;
             modifyInstance.Tracking = instance.Tracking;
             modifyInstance.Type = instance.Type;
             modifyInstance.URL = instance.URL;
             modifyInstance.Vocation = instance.Vocation;
             modifyInstance.VolumeOfBusiness = instance.VolumeOfBusiness;

            modifyInstance.ModifyBy = 1; //Need to get current user
            modifyInstance.ModifyDate = DateTime.Now; 

            this.SubmitChanges();
        }
        public void DeleteCustomer(int id)
        {
            tb_Customer entity = tb_Customers.SingleOrDefault(p => p.Id == id);
            tb_Customers.DeleteOnSubmit(entity);
            this.SubmitChanges();
        }

        public List<tb_Customer> GetCustomerByMasterType(int masterTypeId)
        {
            //var query = (from obj in this.tb_Customers
            //             where obj.tb_Customersz == groupId
            //             select obj).ToList();
            //return query;
            return null;
        }
        #endregion

    }
}
